<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div layout="row" layout-align="center start">

  <card-layout header-css="filter-header" class="centered" style="max-width:980px;width:980px;">

        <header-section>
            <tba-card-filter-header transclude-to="head" flex layout card-title="vm.cardTitle" page-name="{{vm.pageName}}" view-type="vm.viewType" sort-options="vm.sortOptions" on-selected-option="vm.selectedTableOption" filter-model="vm.filter">
            </tba-card-filter-header>
        </header-section>


        <body-section>
          <div ng-if="vm.loading">
            <md-progress-linear class="md-accent" md-mode="indeterminate"></md-progress-linear>
            <span class="md-body-2 layout-padding-left">Loading templates</span>
          </div>

        <div  ng-hide="vm.viewType != 'list'" ng-show="vm.viewType == 'list' && !vm.loading">
           <md-list flex layout-fill class="list-item-table registered-templates">
                        <md-list-item  class="md-secondary" dir-paginate="template in vm.registeredTemplates |orderBy:vm.paginationData.sort |filter:vm.filter|itemsPerPage:vm.paginationData.rowsPerPage" pagination-id="registered-templates"  current-page="vm.currentPage" >
                            <div layout="row" layout-fill>
                              <div flex="40" layout="column" class="item-column md-list-item-text " ng-class="{'disabled':template.state == 'DISABLED'}"
                                   title="{{template.properties.length}} properties configured" ng-click="vm.templateInfo($event,template)">
                                             <span class="item-title" title="{{template.templateName}}">
                                              {{template.templateName}}
                                           </span>


                                <div layout="row" class="column-title column-title-bottom">

                                  <span style="padding-top: 5px;">Template Name</span>
                                  <span ng-if="template.updateAvailable" title="Update available from Repository">
                                      &nbsp;<ng-md-icon icon="update" size="20" style="fill:rgb(0,191,165)"> </ng-md-icon>Update Available
                                  </span>
                                  <span ng-if="template.state == 'DISABLED'" class="push-left-md">DISABLED</span>
                                </div>
                                </div>
                              <div flex="25" layout="column" class="item-column md-list-item-text ">
                                           <span  class="item-title" title="{{feed.active}}" >
                                             {{template.feedsCount}}</span>
                                             <span class="column-title column-title-bottom">
                                             Feeds
                                           </span>
                              </div>
                              <div flex="15" layout="column" class="item-column md-list-item-text ">

                                           <span class="item-title">
                                             {{template.updateDate | date: 'MM/dd/yyyy'}}</span>
                                             <span class="column-title column-title-bottom">
                                             Last Updated
                                           </span>
                                </div>
                                <div flex="20" layout="column" class="item-column md-list-item-text" ng-if="vm.allowExport">
                                    <md-button href="{{template.exportUrl}}"  download layout-align="center" ng-disabled="!template.allowExport">
                                        <ng-md-icon icon="launch" size="20" style="fill:rgb(0,191,165)"> </ng-md-icon>
                                        <span class="push-left-sm">Export</span>
                                    </md-button>
                                </div>

                            </div>
                            <md-divider ng-if="!$last"></md-divider>
                        </md-list-item>
                        <md-list-item  ng-show="vm.loading == false && vm.feedData.length ==0" class="push-left">
                            No results found
                        </md-list-item >
                        <md-divider></md-divider>
                        <md-list-item   layout-align="end center"  layout-row class="pagination-list-item">
                            <dir-pagination-controls pagination-id="registered-templates"
                                                     auto-hide="false"
                                                     max-size="5"
                                                     direction-links="true"
                                                     boundary-links="false"
                                                     template-url="js/common/dir-pagination/dirPagination.tpl.html"
                                                     on-page-change="vm.onPaginationChange(newPageNumber)"
                                                     label='{{"views.all-page.Rows_per_page" | translate}}'
                                                     rows-per-page="vm.paginationData.rowsPerPage"
                                                     rows-per-page-options="vm.paginationData.rowsPerPageOptions"
                                                     class="pagination-row">
                            </dir-pagination-controls>
                        </md-list-item>
                    </md-list>
        </div>
            <div ng-hide="vm.viewType != 'table'" ng-show="vm.viewType == 'table' && !vm.loading">
                <md-table-container>
                    <table md-table md-progress="vm.deferred.promise">
                        <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange" >
                        <tr md-row>
                            <th md-column name="Template" md-order-by="templateName">Template</th>
                            <th md-column name="# of Properties" md-order-by="template.properties.length"># of Properties</th>
                            <th md-column name="Last Updated" md-order-by="updateDate" >Last Updated</th>
                        </tr>
                        </thead>
                        <tbody md-body>
                        <tr md-row ng-repeat="template in vm.registeredTemplates | orderBy: vm.paginationData.sort | filter:vm.filter | limitTo: vm.paginationData.rowsPerPage: (vm.currentPage - 1) * vm.paginationData.rowsPerPage"  >
                            <td md-cell ng-click="vm.templateDetails($event,template)">
                                <ng-md-icon icon="{{template.icon}}" size="20" hide-xs ng-style="{'fill':template.iconColor}">
                                </ng-md-icon>
                                {{template.templateName}}</td>

                            <td md-cell ng-click="vm.templateDetails($event,feed)">
                                {{template.properties.length}}
                            </td>
                            <td md-cell ng-click="vm.templateDetails($event,feed)">{{template.updateDate | date: 'MM/dd/yyyy h:mm:ssa' }}</td>
                            <td md-cell>
                                <md-button href="{{template.exportUrl}}"  layout-align="center">
                                    <ng-md-icon icon="launch" size="20" style="rgb(0,191,165)"> </ng-md-icon>
                                    <span class="push-left-sm">Export</span>
                                </md-button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </md-table-container>

                <md-table-pagination md-limit="vm.paginationData.rowsPerPage" md-page="vm.currentPage" md-total="{{vm.registeredTemplates.length}}" md-on-paginate="vm.onPaginationChange" md-limit-options="[5,10,20,50]"></md-table-pagination>

            </div>
        </body-section>

    </card-layout>
</div>
